package initx

import (
	"back/conf"
	"back/conf/global"
	"github.com/gookit/color"
	"strconv"
	"utilx/dbx"
)

func InitDB(config conf.ServerConf) { //map
	for k, v := range config.DataBase {
		switch k {
		case "redis":
			for i := 0; i < 16; i++ {
				v.DataBase = strconv.Itoa(i)
				redis, err := dbx.InitRedis(v)
				if err != nil {
					continue
				}
				global.RedisBucket[int32(i)] = redis
				color.Greenln(k, v)
			}
		case "postgres":
			postgres, err := dbx.InitPostgres(v)
			if err != nil {
				panic(err)
			}
			global.DB = postgres
			color.Greenln(k, v)
			color.Yellowln(k, v)
		case "mysql1":
			postgres, err := dbx.InitMysql(v)
			if err != nil {
				panic(err)
			}
			global.DB = postgres
			color.Greenln(k, v)
		}
	}
}
